﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace PlugNT.Cms.ActionLabel
{
    public class Article
    {
        /// <summary>
        /// 文章调用类(标题无系统颜色 文字)
        /// </summary>
        /// <param name="topCount"></param>
        /// <param name="clsno"></param>
        /// <param name="type"></param>
        /// <param name="sort"></param>
        /// <param name="postfix"></param>
        /// <param name="isexact"></param>
        /// <returns></returns>
        public static string ViewTxtList(int topCount, string clsno, string sort, int txtNum, bool isTime, bool isShowClsno, bool isColor)
        {
            if (!isColor)
            {
                BLL.Article bll = new BLL.Article();
                StringBuilder strTxt = new StringBuilder();
                DataTable dt = bll.GetList(topCount, clsno, "", sort, "", false);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        string color = "#000000";
                        string img = "1";
                        strTxt.Append("<li>");
                        if (dr["color"] != null)
                        {
                            if (!dr["color"].Equals("#000000"))
                            {
                                img = "2";
                            }
                            color = dr["color"].ToString();
                        }
                        if (!isShowClsno)
                        {
                            strTxt.Append("<span style=\"margin-right:4px;\"><img src=\"images/squ").Append(img).Append(".jpg\" /></span>");
                        }
                        else
                        {
                            Model.ChannelInfo channelInfo = new BLL.Channel().GetChannelInfo(dr["clsno"].ToString());
                            strTxt.Append("<a href=\"Articles.aspx?id=");
                            strTxt.Append(channelInfo.id).Append("\" />").Append("<span style=\"margin-right:4px;color:");
                            strTxt.Append(channelInfo.color).Append(" \">[").Append(channelInfo.clsname).Append("]</span>").Append("</a>");
                        }
                        strTxt.Append("<a target=\"_blank\" title=\"" + dr["Title"].ToString() + "\" href=\"Article.aspx?id=" + dr["Id"] + "\">");

                        strTxt.Append(PlugNT.Common.Utils.CutString(dr["Title"].ToString(), 0, txtNum));

                        strTxt.Append("</a>");

                        if (isTime)
                        {
                            strTxt.Append("<span>[" + string.Format("{0:MM-dd}", dr["AddTime"]) + "]</span>");
                        }
                        strTxt.Append("</li>");
                    }
                }
                else
                {
                    strTxt.Append("<li>暂无数据显示...</li>");
                }
                return strTxt.ToString();
            }
            else
            {
                return ViewTxtList(topCount, clsno, sort, txtNum, isTime, isShowClsno);
            }
        }
        /// <summary>
        /// 文章调用类(文字)
        /// </summary>
        /// <param name="topCount"></param>
        /// <param name="clsno"></param>
        /// <param name="type"></param>
        /// <param name="sort"></param>
        /// <param name="postfix"></param>
        /// <param name="isexact"></param>
        /// <returns></returns>
        public static string ViewTxtList(int topCount, string clsno, string sort, int txtNum, bool isTime, bool isShowClsno)
        {
            BLL.Article bll = new BLL.Article();
            StringBuilder strTxt = new StringBuilder();
            DataTable dt = bll.GetList(topCount, clsno, "", sort, "", false);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    string color = "#000000";
                    string img = "1";
                    strTxt.Append("<li>");
                    if (dr["color"] != null)
                    {
                        if (!dr["color"].Equals("#000000"))
                        {
                            img = "2";
                        }
                        color = dr["color"].ToString();
                    }
                    if (!isShowClsno)
                    {
                        strTxt.Append("<span style=\"margin-right:4px;\"><img src=\"images/squ").Append(img).Append(".jpg\" /></span>");
                    }
                    else
                    {
                        Model.ChannelInfo channelInfo = new BLL.Channel().GetChannelInfo(dr["clsno"].ToString());
                        strTxt.Append("<a href=\"Articles.aspx?id=");
                        strTxt.Append(channelInfo.id).Append("\" />").Append("<span style=\"margin-right:4px;color:");
                        strTxt.Append(channelInfo.color).Append(" \">[").Append(channelInfo.clsname).Append("]</span>").Append("</a>");
                    }
                    strTxt.Append("<a target=\"_blank\" title=\"" + dr["Title"].ToString() + "\" href=\"Article.aspx?id=" + dr["Id"] + "\">");

                    strTxt.Append("<span style=\"color:");
                    strTxt.Append(color).Append(" \">").Append(PlugNT.Common.Utils.CutString(dr["Title"].ToString(), 0, txtNum));
                    strTxt.Append("</span>");
                    strTxt.Append("</a>");

                    if (isTime)
                    {
                        strTxt.Append("<span>[" + string.Format("{0:MM-dd}", dr["AddTime"]) + "]</span>");
                    }
                    strTxt.Append("</li>");
                }
            }
            else
            {
                strTxt.Append("<li>暂无数据显示...</li>");
            }
            return strTxt.ToString();
        }
        /// <summary>
        /// 文章调用类(幻灯片)
        /// </summary>
        /// <param name="topCount"></param>
        /// <param name="clsno"></param>
        /// <param name="type"></param>
        /// <param name="sort"></param>
        /// <param name="postfix"></param>
        /// <param name="isexact"></param>
        /// <returns></returns>
        public static string ViewSlidList(int topCount, string clsno, string sort, int txtNum, bool isTime)
        {
            BLL.Article bll = new BLL.Article();
            StringBuilder strTxt = new StringBuilder();
            StringBuilder strTxt1 = new StringBuilder();
            StringBuilder strTxt2 = new StringBuilder();
            StringBuilder strTxt3 = new StringBuilder();
            DataTable dt = bll.GetList(topCount, clsno, "", sort, "", false);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    strTxt1.Append(dr["Images"].ToString()).Append("|");
                    strTxt2.Append(PlugNT.Common.Utils.CutString(dr["Title"].ToString(), 0, txtNum)).Append("|");
                    strTxt3.Append("Article.aspx?id=").Append(dr["Id"].ToString()).Append("|");
                }
                strTxt.Append("var pics =\"").Append(strTxt1.ToString().TrimEnd(new char[] { '|' })).Append("\" ");
                strTxt.Append("\n");
                strTxt.Append("var texts =\"").Append(strTxt2.ToString().TrimEnd(new char[] { '|' })).Append("\" ");
                strTxt.Append("\n");
                strTxt.Append("var links =\"").Append(strTxt3.ToString().TrimEnd(new char[] { '|' })).Append("\" ");
            }
            else
            {
                strTxt.Append("var pics = var links = var texts = ");
            }
            return strTxt.ToString();
        }
        /// <summary>
        /// 文章调用类(图片)
        /// </summary>
        /// <param name="topCount"></param>
        /// <param name="clsno"></param>
        /// <param name="type"></param>
        /// <param name="sort"></param>
        /// <param name="postfix"></param>
        /// <param name="isexact"></param>
        /// <returns></returns>
        public static string ViewImageList(int topCount, string clsno, string sort, int txtNum, bool isTime)
        {
            BLL.Article bll = new BLL.Article();
            StringBuilder strTxt = new StringBuilder();
            DataTable dt = bll.GetList(topCount, clsno, "", sort, "", false);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    strTxt.Append("<div class=\"hang7-1-text-img\">");
                    strTxt.Append("<a target=\"_blank\" title=\"" + dr["Title"].ToString() + "\" href=\"Article.aspx?id=" + dr["Id"] + "\">");
                    strTxt.Append("<img src=\"" + dr["Images"].ToString() + "\" alt=\"" + dr["Title"].ToString() + "\" />");
                    strTxt.Append("</a>");
                    strTxt.Append("</div>");
                }
            }
            else
            {
                strTxt.Append("暂无数据显示...");
            }
            return strTxt.ToString();
        }


        /// <summary>
        /// 文章调用类(首页新闻资讯栏目)
        /// </summary>
        /// <param name="topCount"></param>
        /// <param name="clsno"></param>
        /// <param name="type"></param>
        /// <param name="sort"></param>
        /// <param name="postfix"></param>
        /// <param name="isexact"></param>
        /// <returns></returns>
        public static string ViewTxtNewsList(int topCount, string clsno, string sort, int txtNum, bool isTime)
        {
            BLL.Article bll = new BLL.Article();
            StringBuilder strTxt = new StringBuilder();
            DataTable dt = bll.GetList(topCount, clsno, "", sort, "", false);
            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    Model.ChannelInfo channelInfo = new BLL.Channel().GetChannelInfo(dr["clsno"].ToString());
                    strTxt.Append("<li><span class=\"font-color1\">[").Append("<a href=\"Articles.aspx?clsno=");
                    strTxt.Append(channelInfo.clsno).Append("\">").Append(channelInfo.clsname).Append("</a>]</span>");
                    strTxt.Append("<span style=\"color: #000000;  width: 289px;\">");
                    strTxt.Append("<a target=\"_blank\" title=\"" + dr["Title"].ToString() + "\" href=\"Article.aspx?id=" + dr["Id"] + "\">" + PlugNT.Common.Utils.CutString(dr["Title"].ToString(), 0, txtNum) + "</a>");
                    strTxt.Append("</span>");
                    if (isTime)
                    {
                        strTxt.Append("<span class=\"font-color2\">" + string.Format("{0:MM-dd}", dr["AddTime"]) + "</span>");
                    }
                    strTxt.Append("</li>");
                }
            }
            else
            {
                strTxt.Append("<li>暂无数据显示...</li>");
            }
            return strTxt.ToString();
        }


        public static string ViewTxtNewsList(int topCount, string clsno, string sort, int txtNum, bool isTime, bool isShowClsName)
        {
            if (!isShowClsName)
            {
                BLL.Article bll = new BLL.Article();
                StringBuilder strTxt = new StringBuilder();
                DataTable dt = bll.GetList(topCount, clsno, "", sort, "", false);
                if (dt.Rows.Count > 0)
                {
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        DataRow dr = dt.Rows[i];
                        Model.ChannelInfo channelInfo = new BLL.Channel().GetChannelInfo(dr["clsno"].ToString());
                        strTxt.Append("<li>·");
                        strTxt.Append("<span style=\"color: #000000;  width: 289px;\">");
                        strTxt.Append("<a target=\"_blank\" title=\"" + dr["Title"].ToString() + "\" href=\"Article.aspx?id=" + dr["Id"] + "\">" + PlugNT.Common.Utils.CutString(dr["Title"].ToString(), 0, txtNum) + "</a>");
                        strTxt.Append("</span>");
                        if (isTime)
                        {
                            strTxt.Append("<span class=\"font-color2\">" + string.Format("{0:MM-dd}", dr["AddTime"]) + "</span>");
                        }
                        strTxt.Append("</li>");
                    }
                }
                else
                {
                    strTxt.Append("<li>暂无数据显示...</li>");
                }
                return strTxt.ToString();
            }
            else
            {
                return ViewTxtNewsList(topCount, clsno, sort, txtNum, isTime);
            }
        }
    }
}
